package com.juyu.miliao.api.dao.mysql;

import com.juyu.miliao.api.domain.UserPhoto;
import org.apache.ibatis.session.SqlSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Repository
public class PrivatePhotoDao {
    @Resource
    private SqlSession sqlSession;

    public List<UserPhoto> getPrivatePhotoById(long id) {
        return sqlSession.selectList("getPrivatePhotoById", id);
    }

    public List<String> getPrivatePhotoFreeByuserId(long userId,int startNum,int pageSize) {
        Map<String,Object> parames = new HashMap<>(3);
        parames.put("userId",userId);
        parames.put("startNum",startNum);
        parames.put("pageSize",pageSize);
        return sqlSession.selectList("getPrivatePhotoFreeByuserId", parames);
    }

    public int deletePrivatePhotoById(int privateId, int userId) {
        Map<String, Object> map = new HashMap<>(4);
        map.put("privateId", privateId);
        map.put("userId", userId);
        return sqlSession.delete("deletePrivatePhotoById", map);
    }

    public int insertPrivatePhoto(UserPhoto entity) {
        return sqlSession.insert("insertPrivatePhoto", entity);
    }

    public UserPhoto getPrivatePhotoByPrivateId(int privateId) {
        return sqlSession.selectOne("getPrivatePhotoByPrivateId", privateId);
    }


    public void updatePrivatePhotoByPicType(int picType,int privateId) {
        Map<String, Object> map = new HashMap<>(4);
        map.put("privateId", privateId);
        map.put("picType", picType);
        sqlSession.update("updatePrivatePhotoByPicType",map);
    }

    public List<UserPhoto> getFreePhotoByUserId(long userId) {
        return sqlSession.selectList("getFreePhotoByUserId",userId);
    }
}
